package cn.ynu.cmrs.activity;

import cn.ynu.cmrs.R;
import cn.ynu.cmrs.MyApplication;
import android.app.TabActivity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.widget.RadioGroup;
import android.widget.TabHost;
import android.widget.RadioGroup.OnCheckedChangeListener;

/**
 * TabActivity, contains most important Activity of program
 * 
 * @author starsfury
 */
@SuppressWarnings("deprecation")
public class MainActivity extends TabActivity {
	TabHost mTabHost;
	RadioGroup mRadioGroup;

	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.maintabs);
		MyApplication.allActivity.add(this);
		
		mTabHost = this.getTabHost();
		/*mTabHost.addTab(mTabHost
				.newTabSpec("TAB_ALLCOURSE")
				.setIndicator("TAB_ALLCOURSE")
				.setContent(
						new Intent(MainActivity.this, AllCourseActivity.class)));*/
		mTabHost.addTab(mTabHost
				.newTabSpec("TAB_ALLCOURSE")
				.setIndicator("TAB_ALLCOURSE")
				.setContent(
						new Intent(MainActivity.this, AllCourse.class)));
		mTabHost.addTab(mTabHost
				.newTabSpec("TAB_VIDEOCOURSE")
				.setIndicator("TAB_VIDEOCOURSE")
				.setContent(
						new Intent(MainActivity.this, VideoCourseActivity.class)));
		mTabHost.addTab(mTabHost
				.newTabSpec("TAB_FAVORITE")
				.setIndicator("TAB_FAVORITE")
				.setContent(
						new Intent(MainActivity.this, FavoriteActivity.class)));
		mTabHost.addTab(mTabHost
				.newTabSpec("TAB_SEARCH")
				.setIndicator("TAB_SEARCH")
				.setContent(new Intent(MainActivity.this, SearchActivity.class)));

		mTabHost.addTab(mTabHost
				.newTabSpec("TAB_MORE")
				.setIndicator("TAB_MORE")
				.setContent(
						new Intent(MainActivity.this, SettingsActivity.class)));
		mRadioGroup = (RadioGroup) this.findViewById(R.id.main_radio);
		mRadioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() {
			@Override
			public void onCheckedChanged(RadioGroup arg0, int rid) {
				// TODO Auto-generated method stub
				switch (rid) {
				case R.id.radio_button0:// All course Activity
					mTabHost.setCurrentTabByTag("TAB_ALLCOURSE");
					break;
				case R.id.radio_button1:// Excellent course Activity
					mTabHost.setCurrentTabByTag("TAB_VIDEOCOURSE");
					break;
				case R.id.radio_button2:// Favorite course Activity
					mTabHost.setCurrentTabByTag("TAB_FAVORITE");
					break;
				case R.id.radio_button3:// Search Activity
					mTabHost.setCurrentTabByTag("TAB_SEARCH");
					break;
				case R.id.radio_button4:// Setting Activity
					mTabHost.setCurrentTabByTag("TAB_MORE");
					break;
				}
			}
		});
	}

	/**
	 * Launch this Activity from the outside
	 *
	 * @param context context from which Activity should be started
	 */
	public static void launch(Context context) {
		Intent intent = new Intent(context, MainActivity.class);
		context.startActivity(intent);
	}

}
